<?php
class UploadsController extends AppController {

	var $name = 'Uploads';
	var $helpers = array('Html', 'Form', 'FileUpload.FileUpload');
	var $components = array('FileUpload.FileUpload');

	function beforeFilter(){
		parent::beforeFilter();
		
		$this->FileUpload->fileModel(null); //Upload by default.
		
		/* defaults to:
		 'jpg' => array('image/jpeg', 'image/pjpeg'),
		 'jpeg' => array('image/jpeg', 'image/pjpeg'),
		 'gif' => array('image/gif'),
		 'png' => array('image/png','image/x-png'),*/

		$this->FileUpload->allowedTypes(array(
            'jpg' => array('image/jpeg','image/pjpeg'), 
            'txt', 
            'gif', 
            'pdf' => array('application/pdf')
		));
	}

	function add() {
		if(!empty($this->data)){
			if($this->FileUpload->success){
				$this->set('photo', $this->FileUpload->finalFile);
			}else{
				$this->Session->setFlash($this->FileUpload->showErrors());
			}
		}
	}

	function delete($id = null) {
		$upload = $this->Upload->findById($id);
		if($this->FileUpload->removeFile($upload['Upload']['name'])){
			if($this->Upload->delete($id)){
				$this->Session->setFlash('Upload deleted');
				$this->redirect(array('action'=>'index'));
			}
		}
	}
}

?>